package com.spring.data.jpa.service.imp;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.data.jpa.domain.User;
import com.spring.data.jpa.repository.UserRepository;
import com.spring.data.jpa.service.UserService;

/**
 * 用户业务服务实现类 
 * @author chang
 *
 */
@Service("userService")
public class UserServiceImpl implements UserService{ 
	
	@Autowired    
	private UserRepository userRepository; //注入UserRepository    
	
	//@Override    
	@Transactional    
	public void saveUser(User user) {
		userRepository.save(user);            
	}   
	//@Override    
	@Transactional(readOnly=true)    
	public User findUserById(Integer id) {       
		return userRepository.findOne(id);    
	}        
	//@Override    
	@Transactional    
	public void updateUser(User user) {        
		userRepository.save(user);    
	}    
	//@Override    
	@Transactional    
	public void deleteUserById(Integer id) {       
		userRepository.delete(id);    
	}
	
	//@Override
	public User findByTheName(String name) {
		return userRepository.findByTheName(name);
	}
	//@Override
	public List<User> findByAccount(String account) {
		return userRepository.findByAccount(account);
	}
	//@Override
	public List<User> findByPassword(String password) {
		return userRepository.findByPassword(password);
	}
	
	//@Override
	public Page<User> findByAccount(String account, Pageable pageable) {
		return userRepository.findByAccount(account, pageable);
	}
	//@Override
	public Map<String, Object> searchByCondition(int page,int start,int limit,User user) {
		return userRepository.searchByCondition(page,start,limit,user);
	}
}
